$(function () {

    getMyProfitList(1);

    $("body").on("click",".qaEarning",function () {
        window.location.href=baseloaction+'/mobile/uc/qa/myQaProfit'
    }).on("click",".extractEarning",function () {
        var ableExtractEarning = $(".ableExtractEarning").text();
        if (ableExtractEarning != 0 && ableExtractEarning > 0){
            //提示信息
            $.confirm('确定要将收益提取到账户吗?',function(){
                extractEarning();
            });
        } else {
            $.toast('没有可提取的收益');
        }
    }).on("click",".u-myQa-tipsBtn",function () {
        $.alert('<span class="fs7">当我提的付费问题被其他用户围观之后,我会得到固定比例的分成收益，这就是问答收益</span>', '<strong><span class="c-orange">" </span>什么是问答收益<span class="c-orange"> "</span></strong>');
        $('.modal-in').find('.modal-button-bold').text('我知道了');
    });


    /**
     * 提取收益到账户
     */
    function extractEarning() {
        $.ajax({
            url:baseloaction +'/mobile/uc/qa/extractEarning',
            type:'post',
            dataType:'json',
            data:'',
            success:function (result) {
                $('.ableExtractEarning').text(0);
                var text = result.message;
                if (text == "围观收益提取成功"){
                    $.toast("收益已提取成功<br>可到"+"'我的账户'"+"中查看");
                }else{
                    $.toast(text);
                }
            },
            error:function (error) {
                $.toast('系统错误，提取到账户失败');
            }
        });
    }

    /**
     * 查询我的收益列表
     * @param pageNo
     */
    function getMyProfitList(pageNo) {
        loadMobilePathData({
            url: baseloaction + '/mobile/uc/qa/ajax/myProfitList',
            contextId: 'qa-myProfit-list',
            params: '',
            pageNo: pageNo,
            pageCall: getMyProfitList,
            callback: function (pageNo) {

            }
        });
    }
});